cmake_minimum_required(VERSION 2.8)
project(yuechuan)
include(cmake/utils.cmake)


set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O -g -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -fno-stack-protector ")
set(CMAKE_C_FLAGS "$ENV{CXXFLAGS} -rdynamic -O -fPIC -ggdb -std=c11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations")
include_directories("yuechuan/include")
include_directories("yuechuan/http")
include_directories("yuechuan/streams")
include_directories("yuechuan/utils")
include_directories("/usr/local/include")    # 添加导入包的文件夹

find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
    include_directories(${OPENSSL_INCLUDE_DIR})
endif ()

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)


set(LIB_SRC
        yuechuan/log.cpp
        yuechuan/util.cpp
        yuechuan/utils/json_util.cpp
        yuechuan/config.cpp
        yuechuan/mutex.cpp
        yuechuan/thread.cpp
        yuechuan/fiber.cpp
        yuechuan/scheduler.cpp
        yuechuan/timer.cpp
        yuechuan/iomanager.cpp
        yuechuan/fd_manager.cpp
        yuechuan/hook.cpp
        yuechuan/address.cpp
        yuechuan/socket.cpp
        yuechuan/uri.rl.cpp
        yuechuan/tcp_server.cpp
        yuechuan/bytearray.cpp
        yuechuan/stream.cpp
        yuechuan/http/http.cpp
        yuechuan/http/httpclient_parser.rl.cpp
        yuechuan/http/http11_parser.rl.cpp
        yuechuan/http/http_parser.cpp
        yuechuan/streams/socket_stream.cpp
        yuechuan/http/http_session.cpp
        yuechuan/http/http_connection.cpp
        yuechuan/http/http_server.cpp
        yuechuan/http/servlet.cpp
        yuechuan/http/servlets/config_servlet.cpp
        yuechuan/http/servlets/status_servlet.cpp
#        yuechuan/module.cpp
#        yuechuan/module.h
        )
#  给文件取别名，方便下面使用，通过${LIB_SRC}即可调用后面配置的文件
set(LIB_LIB
        yuechuan
        pthread
        yaml-cpp
        jsoncpp
        dl
        ${OPENSSL_LIBRARIES})

add_library(yuechuan SHARED ${LIB_SRC})        # 根据后面的文件生成动态库，其中的SHARED换成STATIC即可生成.a的静态文件
force_redefine_file_macro_for_source(yuechuan)
ragelmaker(yuechuan/uri.rl LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/yuechuan)
#target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}/include)
#SET_TARGET_PROPERTIES (yuechuan_static PROPERTIES OUTPUT_NAME "yuechuan")


# Test Items 

# add_executable(test tests/test.cpp)
# add_dependencies(test yuechuan)
# target_link_libraries(test ${LIB_LIB})

# add_executable(test_config tests/test_config.cpp)
# add_dependencies(test_config yuechuan)
# target_link_libraries(test_config ${LIB_LIB})
# force_redefine_file_macro_for_source(test_config)
#
#add_executable(test_thread tests/test_thread.cpp)
#add_dependencies(test_thread yuechuan)
#target_link_libraries(test_thread ${LIB_LIB})
#force_redefine_file_macro_for_source(test_thread)

# add_executable(test_out tests/test_out.cpp)
# add_dependencies(test_out yuechuan)
# target_link_libraries(test_out ${LIB_LIB})
# force_redefine_file_macro_for_source(test_out)

# add_executable(test_util tests/test_util.cpp)
# add_dependencies(test_util yuechuan)
# target_link_libraries(test_util ${LIB_LIB})
# force_redefine_file_macro_for_source(test_util)


# add_executable(test_fiber tests/test_fiber.cpp)
# add_dependencies(test_fiber yuechuan)
# target_link_libraries(test_fiber ${LIB_LIB})
# force_redefine_file_macro_for_source(test_fiber)


# add_executable(test_ucontext tests/test_ucontext.cpp)
# add_dependencies(test_ucontext yuechuan)
# target_link_libraries(test_ucontext ${LIB_LIB})

#add_executable(test_scheduler tests/test_scheduler.cpp)
#add_dependencies(test_scheduler yuechuan)
#target_link_libraries(test_scheduler ${LIB_LIB})
#force_redefine_file_macro_for_source(test_scheduler)
#
#add_executable(test_iomanager tests/test_iomanager.cpp)
#add_dependencies(test_iomanager yuechuan)
#target_link_libraries(test_iomanager ${LIB_LIB})
#force_redefine_file_macro_for_source(test_iomanager)
#
#
#add_executable(test_hook tests/test_hook.cpp)
#add_dependencies(test_hook yuechuan)
#target_link_libraries(test_hook ${LIB_LIB})
#force_redefine_file_macro_for_source(test_hook)

#add_executable(test_address tests/test_address.cpp)
#add_dependencies(test_address yuechuan)
#target_link_libraries(test_address ${LIB_LIB})
#force_redefine_file_macro_for_source(test_address)


#add_executable(test_socket tests/test_socket.cpp)
#add_dependencies(test_socket yuechuan)
#target_link_libraries(test_socket ${LIB_LIB})
#force_redefine_file_macro_for_source(test_socket)

#add_executable(test_bytearray tests/test_bytearray.cpp)
#add_dependencies(test_bytearray yuechuan)
#target_link_libraries(test_bytearray ${LIB_LIB})
#force_redefine_file_macro_for_source(test_bytearray)

#add_executable(test_http tests/test_http.cpp)
#add_dependencies(test_http yuechuan)
#target_link_libraries(test_http ${LIB_LIB})
#force_redefine_file_macro_for_source(test_http)

#add_executable(test_http_parser tests/test_http_parser.cpp)
#add_dependencies(test_http_parser yuechuan)
#target_link_libraries(test_http_parser ${LIB_LIB})
#force_redefine_file_macro_for_source(test_http_parser)

#add_executable(test_tcp_server tests/test_tcp_server.cpp)
#add_dependencies(test_tcp_server yuechuan)
#target_link_libraries(test_tcp_server ${LIB_LIB})
#force_redefine_file_macro_for_source(test_tcp_server)

#add_executable(echo_server examples/echo_server.cpp)
#add_dependencies(echo_server yuechuan)
#target_link_libraries(echo_server ${LIB_LIB})
#force_redefine_file_macro_for_source(echo_server)

#add_executable(test_http_server tests/test_http_server.cpp)
#add_dependencies(test_http_server yuechuan)
#target_link_libraries(test_http_server ${LIB_LIB})
#force_redefine_file_macro_for_source(test_http_server)

add_executable(test_http_connection tests/test_http_connection.cpp)
add_dependencies(test_http_connection yuechuan)
target_link_libraries(test_http_connection ${LIB_LIB})
force_redefine_file_macro_for_source(test_http_connection)

add_executable(test_uri tests/test_uri.cpp)
add_dependencies(test_uri yuechuan)
target_link_libraries(test_uri ${LIB_LIB})
force_redefine_file_macro_for_source(test_uri)
# Test Items end


SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#MESSAGE(${CMAKE_HOST_SYSTEM_NAME})             # 打印系统
